// 统一管理api接口的地方

import http from "../http";

// 测试：获取list的数据  get接口
// export function getList(params) {
//     //params {id:10}
//     // http.get(url地址,{params:{参数},headers:{}})
//     return http.get("/list", { params })
// }

//注意登录
// 测试：获取info的数据  post接口
export function getLogin(data) {
    // http.post(url地址,{参数},{headers})
    return http.post("/loginS", data)
}
export function getSvg(data) {
    // http.post(url地址,{参数},{headers})
    return http.post("/svgCode", data)
}
export function getUpdateId(data) {
    return http.post("/updateId", data)
}


// CSY


// 测试：获取list的数据  get接口
export function getList(params) {
    //params {id:10}
    // http.get(url地址,{params:{参数},headers:{}})
    return http.get("/list", { params })
}

//注意登录
// 测试：获取info的数据  post接口
// export function getLogin(data) {
//     // http.post(url地址,{参数},{headers})
//     return http.post("/login", data)
// }

export function chatInterface(data) {
    console.log('data', data);
    return http.post('/api/chat', {
        messages: data
    }, {
        headers: {
            'Content-Type': 'application/json'
        }
    });
}


export function postUpload(data, setUploadProgress) {
    return http.post(`/api/upload/${data.fileName}`, data.chunk, {
        headers: {
            "Content-Type": "application/octet-stream",
        },
        params: {
            chunkFileName: data.chunkFileName,
            start: data.start
        },
        cancelToken: data.cancelToken.token,  // 使用 cancelToken
        onUploadProgress: (ProgressEvent) => {
            const percentCompleted = Math.round(
                // （progressEvent.loaded 本次上传成功的字节 + start 上次上传成功的字节）/ 总字节数
                // 之前的progressEvent.total是当前总字节数不是总的字节数
                ((ProgressEvent.loaded + data.start) * 100) / data.totaSize
            );

            setUploadProgress((prevProgress) => ({
                ...prevProgress,
                [data.chunkFileName]: percentCompleted,  // 更新分片上传进度
            }));
        },
    });
}

//秒传
export function postVerify(data) {
    return http.post("/api/verify", data)
}


//发布文件
export function postAdd(data) {
    return http.post('/api/add', data)
}

//查找单一文件
export function postFind(data) {
    return http.post('/api/one', data)
}

export function postmerge1(data) {
    return http.post('/api/merge', data)
}

//查找所有
export function postFindAll() {
    return http.get('/api/all')
}

//添加评论
export function postAddComment(data) {
    return http.post('/api/comment', data)
}



//用来回复评论
export function postAddReply(data) {
    return http.post('/api/reply', data)
}


//获取用户评论
export function postgetcomments({ article }) {
    return http.get(`/api/getcomments?id=${article} `)
}

//提交三级评论
export function postAddthree(data) {
    return http.post('/api/addthree', data)
}

//给文章点赞
export function postAddlike(data) {
    return http.post('/api/like', data)
}